package com.socket_hpu;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class server {
    public static void main(String[] args) throws Exception {
        ServerSocket ss = new ServerSocket(8080);
        System.out.println("等待客户端连接!");
        Socket s = ss.accept();
        System.out.println("客户端连接成功!");

        InputStream in = s.getInputStream();
        OutputStream out = s.getOutputStream();

        BufferedReader read = new BufferedReader(new InputStreamReader(in));
        PrintWriter writer = new PrintWriter(out, true);
        Scanner sc = new Scanner(System.in);
        String str = read.readLine();
        System.out.println("客户端说:" + str);

        writer.println("你好,客户端!");
        writer.println("我们来玩猜拳游戏吧!");
        while (true) {
            System.out.print("轮到你出拳了:");
            String res1 = sc.next();
            writer.println(res1);
            String res = read.readLine();    //
            System.out.println("客户端出了:" + res);
            if (res.equals("石头") && res1.equals("剪刀")) {
                System.out.println("你输了");
            } else if (res.equals("石头") && res1.equals("石头")) {
                System.out.println("平局");
            } else if (res.equals("石头") && res1.equals("布")) {
                System.out.println("你赢了");
            } else if (res.equals("剪刀") && res1.equals("石头")) {
                System.out.println("你赢了");
            } else if (res.equals("剪刀") && res1.equals("布")) {
                System.out.println("你输了");
            } else if (res.equals("剪刀") && res1.equals("剪刀")) {
                System.out.println("平局");
            } else if (res.equals("布") && res1.equals("剪刀")) {
                System.out.println("你赢了");
            } else if (res.equals("布") && res1.equals("石头")) {
                System.out.println("你输了");
            } else if (res.equals("布") && res1.equals("布")) {
                System.out.println("平局");
            } else if (!res1.equals("布") && !res1.equals("剪刀") && !res1.equals("石头")) {
                System.out.println("你的输入非法！！！你输了!!!");
            } else if (!res.equals("布") && !res.equals("剪刀") && !res.equals("石头")) {
                System.out.println("对方输入非法！！！你赢了!!!");
            }
//        writer.println("图片正在复制中...");
//        FileInputStream fis = new FileInputStream("F:/361709010316.jpg");
//        byte[] buffer = new byte[1024];
//        int res = fis.read(buffer);
//        while (res > 0) {
//            out.write(buffer, 0, res);
//            res = fis.read();
//        }
//        fis.close();
//           out.close();
        }
    }
}
